package com.ruoyi.system.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.ExplosionProofFacilities;
import com.ruoyi.system.mapper.ExplosionProofFacilitiesMapper;
import com.ruoyi.system.service.ExplosionProofFacilitiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;

import javax.annotation.Resource;
import java.util.List;

/**
 * 防爆设施(ExplosionProofFacilities)表服务实现类
 *
 * @author makejava
 * @since 2022-11-15 14:05:09
 */
@Service
public class ExplosionProofFacilitiesServiceImpl implements ExplosionProofFacilitiesService {
    @Autowired
    private ExplosionProofFacilitiesMapper explosionProofFacilitiesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ExplosionProofFacilities queryById(Integer id) {
        return this.explosionProofFacilitiesDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param explosionProofFacilities 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ExplosionProofFacilities> queryByPage(ExplosionProofFacilities explosionProofFacilities, PageRequest pageRequest) {
        long total = this.explosionProofFacilitiesDao.count(explosionProofFacilities);
        return new PageImpl<>(this.explosionProofFacilitiesDao.queryAllByLimit(explosionProofFacilities, pageRequest), pageRequest, total);
    }

    @Override
    public List<ExplosionProofFacilities> selectList(ExplosionProofFacilities explosionProofFacilities) {
        return explosionProofFacilitiesDao.queryAll(explosionProofFacilities);
    }

    /**
     * 新增数据
     *
     * @param explosionProofFacilities 实例对象
     * @return 实例对象
     */
    @Override
    public ExplosionProofFacilities insert(ExplosionProofFacilities explosionProofFacilities) {
        this.explosionProofFacilitiesDao.insert(explosionProofFacilities);
        return explosionProofFacilities;
    }

    /**
     * 修改数据
     *
     * @param explosionProofFacilities 实例对象
     * @return 实例对象
     */
    @Override
    public ExplosionProofFacilities update(ExplosionProofFacilities explosionProofFacilities) {
        this.explosionProofFacilitiesDao.update(explosionProofFacilities);
        return this.queryById(explosionProofFacilities.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.explosionProofFacilitiesDao.deleteById(id) > 0;
    }

    @Override
    public String importExcel(List<ExplosionProofFacilities> explosionProofFacilitiess, Boolean isUpdateSupport, String operName) {
        if (StringUtils.isNull(explosionProofFacilitiess) || explosionProofFacilitiess.size() == 0) {
            throw new ServiceException("导入用户数据不能为空！");
        }
        explosionProofFacilitiesDao.insertBatch(explosionProofFacilitiess);
        return "成功";
    }
}
